home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / LiveFastStartServer / Open Transport 1.3 / Includes / CIncludes / OpenTptSerial.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-30  |  7.5 KB  |  266 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OpenTptSerial.h
  3.  
  4.     Contains:    Definitions for Serial Port
  5.  
  6.     Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. */
  10.  
  11. #ifndef __OPENTPTSERIAL__
  12. #define __OPENTPTSERIAL__
  13.  
  14. #ifndef __OPENTRANSPORT__
  15. #include <OpenTransport.h>
  16. #endif
  17.  
  18. /*******************************************************************************
  19. ** Module Definitions
  20. ********************************************************************************/
  21. //
  22. // XTI Level
  23. //
  24.  
  25. enum
  26. {
  27.     COM_SERIAL    = 'SERL'
  28. };
  29. //
  30. // Version Number
  31. //
  32. #define kSerialABVersion    "1.1.1"
  33.  
  34. //
  35. // Module Names
  36. //
  37. #define kSerialABName        "serialAB"
  38. #define kSerialName            "serial"
  39. #define kSerialPortAName    "serialA"
  40. #define kSerialPortBName    "serialB"
  41.  
  42. enum
  43. {
  44.     kSerialABModuleID    = 7200
  45. };
  46.  
  47. enum
  48. {
  49.     kOTSerialFramingAsync            = 0x01,        /* Support Async serial mode             */
  50.     kOTSerialFramingHDLC            = 0x02,        /* Support HDLC synchronous serial mode    */
  51.     kOTSerialFramingSDLC            = 0x04,        /* Support SDLC synchronous serial mode    */
  52.     kOTSerialFramingAsyncPackets    = 0x08         /* Support Async "packet" serial mode    */
  53. };
  54.  
  55. /*******************************************************************************
  56. ** IOCTL Calls for Serial Drivers
  57. ********************************************************************************/
  58.  
  59. enum
  60. {
  61.     /* 
  62.      * Set DTR (0 = off, 1 = on)
  63.      */
  64.     I_SetSerialDTR            = MIOC_CMD(MIOC_SRL, 0),
  65.         kOTSerialSetDTROff            = 0,
  66.         kOTSerialSetDTROn            = 1,
  67.     /*
  68.      * Send a break on the line - kOTSerialSetBreakOff = off, kOTSerialSetBreakOn = on,
  69.      * Any other number is the number of milliseconds to leave break on, then
  70.      * auto shutoff
  71.      */
  72.     I_SetSerialBreak        = MIOC_CMD(MIOC_SRL, 1),
  73.         kOTSerialSetBreakOn        = 0xffffffff,
  74.         kOTSerialSetBreakOff    = 0,
  75.     /*
  76.      * Force XOFF state - 0 = Unconditionally clear XOFF state, 1 = unconditionally set it
  77.      */
  78.     I_SetSerialXOffState    = MIOC_CMD(MIOC_SRL, 2),
  79.         kOTSerialForceXOffTrue        = 1,
  80.         kOTSerialForceXOffFalse        = 0,
  81.     /*
  82.      * Send an XON character
  83.      * 0 = send only if in XOFF state, 1 = send always
  84.      */
  85.     I_SetSerialXOn            = MIOC_CMD(MIOC_SRL, 3),
  86.         kOTSerialSendXOnAlways        = 1,
  87.         kOTSerialSendXOnIfXOffTrue    = 0,
  88.     /*
  89.      * Send an XOFF character
  90.      * 0 = send only if in XON state, 1 = send always
  91.      */
  92.     I_SetSerialXOff            = MIOC_CMD(MIOC_SRL, 4),
  93.         kOTSerialSendXOffAlways        = 1,
  94.         kOTSerialSendXOffIfXOnTrue    = 0
  95. };
  96.  
  97. /*******************************************************************************
  98. ** Option Management for Serial Drivers
  99. ********************************************************************************/
  100. /*
  101. ** These options are all 4-byte values.
  102. ** BaudRate is the baud rate.
  103. ** DataBits is the number of data bits.
  104. ** StopBits is the number of stop bits times 10.
  105. ** Parity is an enum
  106. */
  107.  
  108. enum 
  109. {
  110.     SERIAL_OPT_BAUDRATE    = 0x0100,    /* UInt32    */
  111.     SERIAL_OPT_DATABITS    = 0x0101,    /* UInt32    */
  112.     SERIAL_OPT_STOPBITS    = 0x0102,    /* UInt32 10, 15 or 20 for 1, 1.5 or 2    */
  113.     SERIAL_OPT_PARITY    = 0x0103    /* UInt32    */
  114. };
  115.  
  116.     enum ParityOptionValues
  117.     {
  118.         kOTSerialNoParity = 0, kOTSerialOddParity = 1, kOTSerialEvenParity = 2
  119.     };
  120.  
  121. //
  122. // The "Status" option is a 4-byte value option that is ReadOnly
  123. // It returns a bitmap of the current serial status
  124. //
  125. enum
  126. {
  127.     SERIAL_OPT_STATUS = 0x0104,
  128.     
  129.     kOTSerialSwOverRunErr    = 0x01,
  130.     kOTSerialBreakOn        = 0x08,
  131.     kOTSerialParityErr        = 0x10,
  132.     kOTSerialOverrunErr        = 0x20,
  133.     kOTSerialFramingErr        = 0x40,
  134.     kOTSerialXOffSent        = 0x0010000,
  135.     kOTSerialDTRNegated        = 0x0020000,
  136.     kOTSerialCTLHold        = 0x0040000,
  137.     kOTSerialXOffHold        = 0x0080000,
  138.     kOTSerialOutputBreakOn    = 0x1000000
  139. };
  140.  
  141. //
  142. // The "Handshake" option defines what kind of handshaking the serial port
  143. // will do for line flow control.  The value is a 32-bit value defined by
  144. // the function or macro SerialHandshakeData below.
  145. // For no handshake, or CTS handshake, the onChar and offChar parameters
  146. // are ignored.
  147. //
  148. enum
  149.     SERIAL_OPT_HANDSHAKE = 0x0105
  150. };
  151. //
  152. // These are bits to enable specific types of handshaking
  153. //
  154. enum
  155. {
  156.     kOTSerialXOnOffInputHandshake    = 1,    /* Want XOn/XOff handshake for incoming characters    */
  157.     kOTSerialXOnOffOutputHandshake    = 2,    /* Want XOn/XOff handshake for outgoing characters    */
  158.     kOTSerialCTSInputHandshake        = 4,    /* Want CTS handshake for incoming characters        */
  159.     kOTSerialDTROutputHandshake        = 8        /* Want DTR handshake for outoing characters        */
  160. };
  161.  
  162. #ifdef __cplusplus
  163.  
  164. inline UInt32 OTSerialHandshakeData(UInt16 type, UInt8 onChar, UInt8 offChar)
  165. {
  166.     return (((UInt32)type) << 16) | (((UInt32)onChar) << 8) | offChar;
  167. }
  168.  
  169. #else
  170.  
  171. #define OTSerialHandshakeData(type, onChar, offChar)    \
  172.     ((((UInt32)type) << 16) | (((UInt32)onChar) << 8) | offChar)
  173.     
  174. #endif
  175. //
  176. // The "RcvTimeout" option defines how long the receiver should wait before delivering
  177. // less than the RcvLoWat number of characters.  If RcvLoWat is 0, then the RcvTimeout
  178. // is how long a gap to wait for before delivering characters.  This parameter is advisory,
  179. // and serial drivers are free to deliver data whenever they deem it convenient.  For instance,
  180. // many serial drivers will deliver data whenever 64 bytes have been received, since 64 bytes
  181. // is the smallest STREAMS buffer size. Keep in mind that timeouts are quantized, so be sure to
  182. // look at the return value of the option to determine what it was negotiated to.
  183. //
  184. enum
  185.     SERIAL_OPT_RCVTIMEOUT = 0x0106
  186. };
  187. //
  188. // This option defines how characters with parity errors are handled.
  189. // A 0 value will disable all replacement.  A single character value in the low
  190. // byte designates the replacement character.  When characters are received with a 
  191. // parity error, they are replaced by this specified character.  If a valid incoming
  192. // character matches the replacement character, then the received character's msb is
  193. // cleared. For this situation, the alternate character is used, if specified in bits
  194. // 8 through 15 of the option long, with 0xff being place in bits 16 through 23.
  195. // Whenever a valid character is received that matches the first replacement character,
  196. // it is replaced with this alternate character.
  197. //
  198. enum
  199.     SERIAL_OPT_ERRORCHARACTER = 0x0107
  200. };
  201.  
  202. #ifdef __cplusplus
  203.  
  204. inline UInt32 OTSerialSetErrorCharacter(UInt8 rep)
  205. {
  206.     return rep & 0xff;
  207. }
  208.  
  209. inline UInt32 OTSerialSetErrorCharacterWithAlternate(UInt8 rep, UInt8 alternate)
  210. {
  211.     return (((rep & 0xff) | ((alternate & 0xff) << 8)) | 0x80000000L);
  212. }
  213.  
  214. #else
  215.  
  216. #define OTSerialSetErrorCharacter(rep)    \
  217.     ((rep) & 0xff)
  218.  
  219. #define OTSerialSetErrorCharacterWithAlternate(rep, alternate)    \
  220.     ((((rep) & 0xff) | (((alternate) & 0xff) << 8)) | 0x80000000L)
  221.  
  222. #endif
  223. //
  224. // The "ExtClock" requests an external clock.  A 0-value turns off external clocking.
  225. // Any other value is a requested divisor for the external clock.  Be aware that
  226. // not all serial implementations support an external clock, and that not all
  227. // requested divisors will be supported if it does support an external clock.
  228. //
  229. enum
  230.     SERIAL_OPT_EXTCLOCK = 0x0108
  231. };
  232. //
  233. // The "BurstMode" option informs the serial driver that it should continue looping,
  234. // reading incoming characters, rather than waiting for an interrupt for each character.
  235. // This option may not be supported by all Serial driver
  236. //
  237. enum
  238.     SERIAL_OPT_BURSTMODE = 0x0109
  239. };
  240.  
  241. //
  242. // Default attributes for the serial ports
  243. //
  244. enum
  245. {
  246.     kOTSerialDefaultBaudRate        = 19200,
  247.     kOTSerialDefaultDataBits        = 8,
  248.     kOTSerialDefaultStopBits        = 10,
  249.     kOTSerialDefaultParity            = kOTSerialNoParity,
  250.     kOTSerialDefaultHandshake        = 0,
  251.     kOTSerialDefaultOnChar            = ('Q' & ~0x40),
  252.     kOTSerialDefaultOffChar            = ('S' & ~0x40),
  253.     kOTSerialDefaultSndBufSize        = 1024,
  254.     kOTSerialDefaultRcvBufSize        = 1024,
  255.     kOTSerialDefaultSndLoWat        = 96,
  256.     kOTSerialDefaultRcvLoWat        = 1,
  257.     kOTSerialDefaultRcvTimeout        = 10
  258. };
  259.  
  260. #endif    /* __OPENTPTSERIAL */
  261.